package com.ocm.tourism.core.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ocm.tourism.core.dao.FestivalDao;
import com.ocm.tourism.core.domain.Festival;

@Service
public class FestivalServiceImpl implements FestivalService {

   @Autowired
   FestivalDao festivalDao;

   @Override
   public List<Festival> findAll() {
      List<Festival> festivals = this.festivalDao.findAll();
      return festivals;
   }

   @Transactional
   public void save(Festival festival) {
      if (festival.getId() == null || festival.getId() == 0){
         this.festivalDao.save(festival);
      } else {
         this.festivalDao.update(festival);
      }
   }

   @Override
   public Festival findFestival(long id) {
      Festival festival = this.festivalDao.find(id);
      return festival;
   }

   @Transactional
   public void delete(long id) {
      this.festivalDao.remove(id);
   }
}
